/*
 * @Author: yangrongxin
 * @Date: 2021-05-17 11:02:04
 * @LastEditors: guoju
 * @LastEditTime: 2022-01-07 11:30:55
 */
// const banner = require('./banner.ef81f0fa.jpg');
function getInfo() {
  const headers = new Headers();
  headers.append('Content-Type', 'text/plain');

  const request = new Request(
    // banner,
    // 'https://www.apprx.cn/img/banner.ef81f0fa.jpg',
    // 'http://e.hiphotos.baidu.com/image/pic/item/a1ec08fa513d2697e542494057fbb2fb4316d81e.jpg',
    'http://localhost:3000',
    {
      headers,
      // mode: 'no-cors',
      credentials: 'omit',
    },
  );
  // fetch(banner, {
  // fetch('https://www.apprx.cn/img/banner.ef81f0fa.jpg', {
  fetch(request)
    .then((res: any) => {
      if (res.ok) {
        // 创建一个reader
        const reader = res.body.getReader();
        const stream = new ReadableStream({
          start(controller) {
            function push() {
              reader.read().then(({ done, value }: any) => {
                if (done) {
                  controller.close();
                  console.log('获取数据结束');
                  return;
                }
                controller.enqueue(value);
                push();
              });
            }
            push();
          },
        });
        console.log('stream', stream);
        return new Response(stream, {
          headers: { 'Content-Type': 'text/html' },
        });
      }
      console.log('请求失败');
      // return res.blob();
    })
    .then((res) => {
      console.log('sres', res);
    });

  console.log('headers', headers.get('Content-Type'));
}

// getInfo();
